Home Java Docker
Home     Java

Java Topic

What is Java
History of Java
Freature of Java
Difference Between Java & C++
Java Environment Set Up
Java Hello World Program & its Internal Process
Java Hello World Program
JDK, JRE and JVM
Java Variables
Java Data Types & Unicode System
Java Operators
Java Keywords
Java Control Statements
Java if else
Java switch
Java for loop
Java While loop
Java Do While loop
Java break
Java continue
Java Oops Concept
Java Object & Class
Java Method
Java Constructor
Java Static Keyword
Java this Keyword
Java Inheritance
Java Hybrid Inheritance
Aggregation(HAS-A)
Java Polymorphism
Java method overloading
Java method overriding
Java Runtime polymorphism
Java Dynamic Binding
Super keyword
Final keyword
Difference Between method overloading and method overriding
Java Abstraction
Java Interface
Abstract class vs Interface
Java Encapsulation
Java Package
Java Access Modifiers
covariant return type
Instance initializer block
Java instanceof operator
Object Cloning in Java
Wrapper classes in Java
Java Strictfp Keyword
Recursion in Java
Java Command Line Arguments
Difference between object and class
Java String
Java String Class
Java Immutable String
Java Immutable Class
String Buffer
String Builder
String Buffer vs String
String Builder vs String Buffer
String Tokenizer in Java
Java Array
Java Exceptions Handling
Java Try-Catch block
Java Multiply Catch Block
Java Finally Block
Java Throws Keyword
Java Throw Keyword
Java Exception Propagation
Java Throw vs Throws
Final vs Finally vs Finalize
Exception Handling With Method Overridding
Java Multithreading
Lifecycle and States of a Thread in Java
How to create a thread in Java
Thread Scheduler in Java
Sleeping a thread in Java
Calling run() method
Joining a thread in Java
Naming a thread in Java
Thread Priority
Daemon Thread
Thread Pool
Thread Group
Shutdown hook
Multitasking vs Multithreading
Garbage Collection
RunTime Class
Java Synchronization
Synchronized block in Java
Static Synchronization in Java
Deadlock in Java
Inter Thread Communication in Java
Interrupting Thread in Java
Reentrant Monitor in Java
Java Applet
Animation in Applet
EventHandling in Applet
Display image in Applet
Displaying Graphics in Applet
Parameter in Applet
Java 8 Features
Java Lambda Expressions
Method References
Functional Interfaces
Java 8 Stream
Base64 Encode Decode
Default Method
for Each() Method
Collectors class
String Joiner Class
Optional Class
JavaScript Nashron
Parallel Array Sort
Type Interface
Parameter Reflection
Type and Repeating Annotations
JDBC Improvements

Java Hello World Program

In this part, we will learn how to create a simple Java program. After installing the JDK,
we can simply construct a basic hello Java application.

To write a simple Java program, you must first create a class that has the main function.
First, let us clarify the prerequisite.

Table Of Content

  • Java Program Hello World Example
  • Java Hello World Example Requirements
  • Java Hello World Example
  • Keyword we use in our first java program
  • Internal detail how java program execute
  • What is bytecode in java ?





Java Hello World Example Requirements

To run Java programs, you must have the following software or applications properly installed:

  • Install the JDK. Download and install the JDK if it is not already installed.
  • Sets the path of the jdk/bin directory. See how to set path of jdk directory
  • Now, Writing first Java Programs.

Java Example

Let's have a quick look at Simple Java hello world program example


  /* This is first java program 
   This will print 'Hello Alok'  
   as the output */  

 class Simple{  
public static void main(String args[ ]){
System.out.println("Hello Alok" );
}
}

Output:

Hello Alok 




Keyword we use in our first java program

In the above Java program you have use following keyword


  • class - class is a keyword is used to define a class in java program.
  • public - The public keyword is an access modifier that set visibility and accessibility . public indicates it is visible to everyone.
  • Static - Static is a keyword any method that is declared as static is known as a static method. The primary advantage of the static method is that it does not need the object to be invoked. Because the main() function is run by the JVM, As a result, memory is saved.
  • void - The Void method returns nothing. It indicates it does not return any value. If it is int it will return value you will these things later
  • String[] args or String args[] - For command line arguments, use String[] args or String args[].
  • main - Main keywoed specify the program's starting point.
  • System.out.println() -To print the sentence in output screen, we use System.out.println() . System is a class, 'out' is a PrintStream class object, and 'println()' is a PrintStream class function.



Internal detail how java program execute

Till now,We have learnt how to compile and run a java programme, as well as about the first java programme.
Here, we'll discover what occurs when Java applications are compiled and executed.


What happens at compile time?


At compile time, java file is compiled by java compiler and converts the java code or source code into bytecode i.e .class file

  /* This is my first java program 
   This will print 'Hello World!'  
   as the output */  

 class Simple{  
public static void main(String args[ ]){
System.out.println("Hello World!" );
}
}

Output:

Hello World! 



What happens at run time?

At the run time following steps are performed:


  • Class File
  • Classloader
  • Bytecode verifier
  • Interpreter
  • Runtime
  • Hardware
  • Class file - Class file are the file that contain java byte code with .class extension.
  • Classloader - Classloader is the part of jvm that is used to load the class file.
  • Bytecode Verifier - Bytecode Verifier checks the code fragments for illegal code that can violate access right to objects.
  • Interpreter - Interpreter read bytecode stream then execute the instruction.
  • RunTime - Java Runtime is a software that java program require to run.



What is bytecode in java?


Bytecode in java is just a symbol and each symbol taking one byte in memory that is the reason is called bytecode. Bytecode i.e .class file is generated by the java compiler and after compilation of java source code bytecode is generated, now these bytecode are loaded into java virtual machine(JVM) and then interpreted and then execute. Java programming language is WORA(Write Once Run Anywhere) programming language i.e it is reusable and it save time too.

  • Java bytecode is portable
  • Java bytecode is platform independent


java file(source file)→compiler→.class file(bytecode)→machine code

JDK JRE and JVM Next »
« Perv Next »


Post your comment





Read Next Topic
Java Tutorial - Topic
What is Java
History of Java
Freature of Java
Difference Between Java & C++
Java Environment Set Up
Java Hello World Program & its Internal Process
JDK, JRE and JVM
Java Variables
Java Data Types & Unicode System
Java Operators
Java Keywords
Java Naming Convention
Read Other Java Chapter
Java Topic
Java Basic Tutorial
Java Control Statements
Java Classes & Object
Java Inheritance
Java Polymorphism
Java Abstraction
Java Encapsulation
Java OOPs Miscellaneous
Java Array
Java String
Java Exception Handling
Java Multithreading
Java Synchronization
Java Applet
Java 8 Features
Java 9 Features
Java Collection
Java Mcq
Java Interview Question
Tools
  

Useful Links

  • Home
  • Blog
  • About us
  • Contact Us
  • Privacy policy

Contact Us

Police Colony
Patna, Bihar
India

Email:

About DockerTpoint


India's largest site for Programming Tutorial as well as BANK, SSC, RAILWAY exam
and Campus placement preparation.